package frontend.model.reports;

import backend.model.admin.Employee;
import backend.model.worklog.WorkLog;
import shared.util.CalendarUtils;

import java.io.Serializable;
import java.util.List;

public class CommutersReportEntry implements Serializable, Comparable {

    private Employee employee;
    private int daysWithNormalHours = 0;
    private int daysWithOvertime = 0;

    public CommutersReportEntry(List<WorkLog> workLogList) {
        this.employee = workLogList.get(0).getEmployee();
        for (WorkLog workLog : workLogList) {
            if (passesAllCriteria(workLog)) {
                if (workLog.getHours() <= 8) {
                    daysWithNormalHours ++;
                } else {
                    daysWithOvertime ++;
                }
            }
        }
    }

    private boolean passesAllCriteria(WorkLog workLog) {
        return !CalendarUtils.isWeekendDay(workLog.getDate())
            && workLog.getProject().getIsDirectPayment()
            && workLog.getWorkplace().getIsDeducted();
    }

    public String getIdentificationCard() {
        return employee.getIdentificationCard();
    }

    public Employee getEmployee() {
        return employee;
    }

    public int getDaysWithNormalHours() {
        return daysWithNormalHours;
    }

    public int getDaysWithOvertime() {
        return daysWithOvertime;
    }

    @Override
    public int compareTo(Object o) {
        CommutersReportEntry other = (CommutersReportEntry) o;
        return this.employee.compareTo(other.employee);
    }
}
